﻿using Sui.Domain.Repository;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sui.Domain.App
{
    public class TablesApp: AppBase
    {
        private ITablesRepository service = new TablesRepository(conn);
        public DataTable GetDataTable()
        {
            //string strSql = $"select *from Tables where db_name='{dbName}'";
            string strSql = $"select *from Tables order by modify_time";
            DbCommand cmd = db.GetSqlStringCommond(strSql);
            DataTable dt = db.ExecuteDataTable(cmd);
            return dt;
        }

        public int Save(TablesEntity entity,out string id,out DateTime? creator_time)
        {
            if (string.IsNullOrEmpty(entity.id))
            {
                entity.Create();
                id = entity.id;
                creator_time = entity.creator_time;
                return service.Insert(entity);
            }
            else
            {
                entity.Modify(entity.id);
                id = entity.id;
                creator_time = entity.creator_time;
                return service.Update(entity);
            }
        }
    }
}
